//
//  timer.cpp
//  Sinnca Engine v2
//
//  Created by Ryan Oldis on 10/14/11.
//  Copyright 2011 Sinnca Studios. All rights reserved.
//

#include "timer.h"

globalTimer* globalTimer::_instance = NULL;

globalTimer* globalTimer::Instance()
{
	if (_instance == NULL)
	{
		_instance = new globalTimer();
	}
	
	return _instance;
}

globalTimer::globalTimer()
{
	
}



timer::timer()
{
	startTicks = 0;
	pauseTicks = 0;
	
	started = false;
	paused = false;
}

void timer::start()
{
	started = true;
	paused = false;
	
	startTicks = SDL_GetTicks();
}

void timer::pause()
{
	if ((started == true) && (paused == false))
	{
		paused = true;
		pauseTicks = SDL_GetTicks() - startTicks;
	}
}

void timer::resume()
{
	if (paused == true)
	{
		paused = false;
		
		startTicks = SDL_GetTicks() - pauseTicks;
		
		pauseTicks = 0;
	}
}


int timer::getTicks()
{
	if (started == true)
	{
		if (paused == true)
		{
			return pauseTicks;
		} else {
			
			return SDL_GetTicks() - startTicks;
		}
	}
	
	return 0;
}


